using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using ZxcRP.Runtime.Renderers;
using Renderer = ZxcRP.Runtime.Renderers.Renderer;

namespace ZxcRP.Runtime
{
    /// <summary>
    /// 渲染管线入口，继承自RenderPipeline这个抽象类，
    /// 当unity进行渲染的时候，会调用这个管线的Render方法
    /// </summary>
    public class ZxcRenderPipeline : RenderPipeline
    {
        /// <summary>
        /// 暂时缓存在这里，后面可通过配置来指定
        /// </summary>
        private PolyRenderer polyRenderer = new PolyRenderer();
        
        protected override void Render(ScriptableRenderContext context, Camera[] cameras)
        {
            // 每个Camera对应一个Renderer，从Camera的Renderer组件上获取
            foreach (var camera in cameras)
            {
                var rendererData = camera.GetComponent<RendererData>();
                if (rendererData == null && camera.cameraType == CameraType.Game) continue;
                // 场景摄像机都用Poly
                if (rendererData == null)
                {
                    rendererData = camera.gameObject.AddComponent<RendererData>();
                    rendererData.rendererType = RendererType.Poly;
                }
                if(rendererData.rendererType == RendererType.Poly)
                {
                    polyRenderer.Render(context, camera);
                }
            }
        }

        protected override void Dispose(bool disposing)
        {
            polyRenderer.Dispose();
        }
    }
}

